window.onload = function() {
}
function supplier_supplierSearchClick() {
    supplier_supplierSearch(1, "", "", "1");
    setSearchOrder("orderHead");
}
function supplier_supplierSearch(intCurPage, strOrderColumn, strOrder, strFlag, pageSize) {
    if (strFlag == "1"){
        ajaxRequest(getHost()+"supplier/supplierList/search", {
            "curPage"       : intCurPage,
            "pageSize"      : pageSize,
            "SupplierId"    : getValue("txtSupplierId"),
            "SupplierName"  : getValue("txtSupplierName"),
            "SaleTp"        : getRadioValue("rdoSaleTp"),
            "ProvCode"      : getSelectedValue("selProv"),
            "Position"      : getValue("txtPosition"),
            "SupplierStatus"    : getRadioValue("rdoSupplierStatus"),
            "SupplierScale" : getCheckboxValue("chkSupplierScale"),
            "CreateDateFrom"    : getValue("txtCreateDateFrom"),
            "CreateDateTo"  : getValue("txtCreateDateTo"),
            "ContractNo"    : getValue("txtContractNo"),
            "Tel"           : getValue("txtTel"),
            "Mobile"        : getValue("txtMobile"),
            "Fax"           : getValue("txtFax"),
            "Email"         : getValue("txtEmail"),
            "OrderCountFrom"    : getValue("txtOrderCountFrom"),
            "OrderCountTo"  : getValue("txtOrderCountTo"),
            "Flag"          : strFlag
        }, supplier_supplierListView);
    } else {
        ajaxRequest(getHost()+"supplier/supplierList/search", {
            "curPage"       : intCurPage,
            "pageSize"      : pageSize,
            "orderColumn"   : strOrderColumn,
            "order"         : strOrder,
            "Flag"          : strFlag
        }, supplier_supplierListView);
    }
}

function supplier_supplierSearchHide() {
    var objDiv = document.getElementById("searchDetail");
    if (objDiv.style.display == "none") {
        objDiv.style.display = "block";
    } else if (objDiv.style.display == "block") {
        objDiv.style.display = "none";
    } else {}
}
function supplier_supplierSearchClearClick() {
    //clearErrorMsg();
    objAttr("#searchDetail1 input[type='text']", "value", "");
    objAttr("#searchDetail input[type='text']", "value", "");
    objAttr("#searchDetail1 option[value='']", "selected", "selected");
    objAttr("#searchDetail option[value='']", "selected", "selected");
    objAttr("#searchDetail1 input[type='radio'][value='']", "checked", "checked");
    objAttr("#searchDetail input[type='radio'][value='']", "checked", "checked");
    objAttr("#searchDetail1 input[type='checkbox']", "checked", "");
    objAttr("#searchDetail input[type='checkbox']", "checked", "");
}

function supplier_supplierListView(data) {
    var arrMsg = new Array();
    if (data.count <= 0){
        setTableData("dataTable", data.searchData, null, null);
        pageCreat(1, 0,"pageHead", "orderHead");
        pageCreat(1, 0,"pageFoot", "orderHead");
    }
    if(arrMsg.length>0){
        //setErrorMsg(arrMsg, 600);
        return;
    }
    pageCreat(data.curPage, data.count, "pageHead", "orderHead");
    pageCreat(data.curPage, data.count, "pageFoot", "orderHead");

    arrCols = new Array(
            "supplier_setRowNo(_rowno)",
            "supplier_setIdA(SUPPLIER_ID,SUPPLIER_NO)",
            "supplier_setNameA(SUPPLIER_NAME,HOMEPAGE_URL)",
            "PROV_CODE",
            "supplier_setStatus(STATUS)",
            "LAST_ORDER_DATE",
            "ORDER_COUNT",
            "supplier_setEdit(SUPPLIER_NO)");
    arrColStyle = new Array(
            "text-align:right",
            "",
            "",
            "text-align:center",
            "text-align:center",
            "text-align:right",
            "text-align:right",
            "text-align:center");
    arrRows = new Array(
            "",
            "BListTableGray"
           );
    setTableData("dataTable", data["searchData"], arrCols, arrColStyle,false,arrRows);

    if (data.Parameter != undefined) {
        setValue("txtSupplierId", data.Parameter.SupplierId);
        setValue("txtSupplierName", data.Parameter.SupplierName);
        setRadioByValue("rdoSaleTp", data.Parameter.SaleTp);
        setSelectedByValue("selProv", data.Parameter.ProvCode);
        setValue("txtPosition", data.Parameter.Position);
        setRadioByValue("rdoSupplierStatus", data.Parameter.SupplierStatus);
        setCheckBoxByValue("chkSupplierScale", data.Parameter.SupplierScale);
        setValue("txtCreateDateFrom", data.Parameter.CreateDateFrom);
        setValue("txtCreateDateTo", data.Parameter.CreateDateTo);
        setValue("txtContractNo", data.Parameter.ContractNo);
        setValue("txtTel", data.Parameter.Tel);
        setValue("txtMobile", data.Parameter.Mobile);
        setValue("txtFax", data.Parameter.Fax);
        setValue("txtEmail", data.Parameter.Email);
        setValue("txtOrderCountFrom", data.Parameter.OrderCountFrom);
        setValue("txtOrderCountTo", data.Parameter.OrderCountTo);
    }
}

function supplier_setRowNo(_rowno) {
    var intCurPage  = getCurPage();
    var intPageSize = getPageSize();
    return (intCurPage - 1) * intPageSize + _rowno + 1;
}

function supplier_setIdA(strId, strNo) {
    return "<a href=\"" + getHost()+"supplier/supplierView/index/SupplierNo/"+ strNo + "\">" + strId + "</a>";
}

function supplier_setNameA(strName, strUrl) {
    return "<a target=\"_blank\" href=\"" + strUrl + "\">" + strName + "</a>";
}

function supplier_setStatus(strStatus) {
    if (strStatus == "1") {
        return getLabel("supplier_00001_Trust");
    } else if (strStatus == "2") {
        return getLabel("supplier_00001_NoTrust");
    } else {
        return "";
    }

}

function supplier_setEdit(strNo) {
    return "<input type=\"button\" class=\"BGrayBtn\" value=\""
        + getLabel("supplier_00001_Edit") + "\" onclick=\"supplier_Edit('"+ strNo +"')\"/>";
}

function supplier_Add() {
    window.location.href=getHost()+"supplier/supplierEdit/index/";
}

function supplier_Edit(strNo) {
    window.location.href=getHost()+"supplier/supplierEdit/edit/SupplierNo/" + strNo;
}

function supplier_downloadFile() {
    document.supplierListForm.action = getHost()+"supplier/supplierList/download/";
    document.supplierListForm.submit();
}

function gotoPage(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function firstPage(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function prePage(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function nextPage(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function lastPage(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function orderSearch(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}
function sizeChangeSearch(strPageContainerId, strOrderContainerId) {
    supplier_supplierSearch(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}